<tagLib name="html" />
<include file="Public:header" />
<style>
    /*#leftPart{float:right;}
    #rightPart{float:left;}
    div.content{width:1000px !important;}*/
    #dg.tr {overflow: visible !important;height:auto}
    #borrow.tr {overflow: visible !important;height:auto}
    div.datagrid-cell{height: auto !important;}
</style>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/icon.css">
	
<div id="main" class="main" >
<div class="content">
    <form method='post' id="form1" action="__URL__/update/" >
<div class="title">修改入住单 [ <input type="submit" value="保 存" class="small submit"> <a href="javascript:history.back()">返回列表</a>    <a href="__APP__/Housestats">返回房态</a>]
 <b style="margin-left:10px;">操作人</b>：{$vo.user_id|getModelName=User,nickname}
</div>
<div id="tt" class="easyui-tabs">
<!--左边栏-->
<div id="leftPart" title="基本信息">
            <table cellpadding=3 cellspacing=3>
    <tr>
        <td class="tRight" >预订单号：</td>
        <td class="tLeft" >
            <eq name="_REQUEST.return" value="home">
            <input type="hidden" name="jumpUrl" value="__APP__/Public/main">
        </eq> 

            {$vo.order_id|getModelName='Order','order_no'}
        </td>
    </tr>
    <tr>
        <td class="tRight" >入住单号：</td>
        <td class="tLeft" >{$vo.checkin_no}      
        </td>
    </tr>
    <tr>
        <td class="tRight" ><span class="red">*</span>预订人：</td>
        <td class="tLeft" >
            <input type="hidden" name="member_id" value="{$vo.member_id}" ><a href="__APP__/Member/edit/id/{$vo.member_id}" target="_blank" >{$vo.member_name}</a>
        </td>
    </tr>
<tr>
	<td class="tRight" >房型：</td>
	<td class="tLeft">{$vo.room_id|getModelName=Room,house_id|getModelName=House} </td>
</tr>
<tr id="room_tr">
	<td class="tRight" ><span class="red">*</span>入住房间：</td>
	<td class="tLeft">
            <input type="hidden" id="room_id" name="room_id" value="{$vo.room_id}">
            <input type="text" id="room_no" name="room_no" value="{$vo.room_no}" readonly>
        </td>
</tr>
<tr>
	<td class="tRight" ><span class="red">*</span>入住：</td>
        <td class="tLeft" ><input type="text" class="medium" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="start_time" id="start_time1" value="{$vo.start_time|toDate}">
             &nbsp;&nbsp;<span class="red">*</span>离开：
            <input type="text" class="medium bLeft" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="end_time" id="end_time" value="{$vo.end_time|toDate}">
             &nbsp;&nbsp;实际离开：
            <input type="text" class="medium bLeft" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="end_realtime" id="end_realtime" value="{$vo.end_realtime|toDate}">
        </td>
</tr>
<tr>
	<td class="tRight" ><span class="red">*</span>入住人：</td>
	<td class="tLeft" >
            <input type="text" class="large" id="person_name" name="person_name" value="{$vo.person_name}">
        </td>
</tr>
<tr>
	<td class="tRight" >入住人数：</td>
	<td class="tLeft" >
            <input type="text" class="medium bLeft" name="person_num" value="{$vo.person_num}"></td>
</tr>
<tr>
	<td class="tRight" >预付款：</td>
	<td class="tLeft" ><input type="text" class="medium bLeft" name="advance_pay" id="advance_pay" value="{$vo.advance_pay}"></td>
</tr>
<tr>
	<td class="tRight" style="background:red;">押金：</td>
	<td class="tLeft" ><input type="text" class="medium bLeft" name="deposit" id="deposit" value="{$vo.deposit}" ></td>
</tr>
<tr>
	<td class="tRight" >已消费金额：</td>
	<td class="tLeft" ><input type="text" class="medium bLeft" name="cost_pay" value="{$vo.cost_pay}"></td>
</tr>
<tr>
	<td class="tRight" >结帐时间：</td>
	<td class="tLeft" ><input type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="balance_time" value="{$vo.balance_time|toDate}"></td>
</tr>
<tr>
	<td class="tRight" >结帐金额：</td>
	<td class="tLeft" ><input type="text" class="medium bLeft" name="balance_money" value="{$vo.balance_money}"></td>
</tr>

<tr>
	<td class="tRight tTop">备注说明：</td>
	<td class="tLeft"><textarea class="large bLeft"  name="remark" rows="5" cols="57">{$vo.remark}</textarea></td>
</tr>
<tr>
	<td class="tRight">状态：</td>
	<td class="tLeft">
            <select class="middle bLeft"  name="status">
                 <volist name="checkinStatus" id="stvo">
                     <option value="{$key} " <eq name='vo.status' value='$key'>selected</eq> >{$stvo}</option>
                </volist>
            </select>
            &nbsp;&nbsp;提醒时间：<input type="text" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="medium bLeft" name="alert_time" value="{$vo.alert_time|toDate}">
        </td>
</tr>
<tr>
	<td></td>
	<td class="center">
        <input type="hidden" value="{$vo.id}" name="id">
	<input type="submit" value="保 存" class="small submit">
	<input type="reset" class="reset imgButton" onclick="javascript:history.back()" value="返回" >
	</td>
</tr>
</table>
    
    </form>
        </div>
        <!--消费记录-->
        <div id="rightPart" title="消费记录">
            <div class="demo-info" style="margin-bottom:4px">
                <div class="red">&nbsp;房租总额：{$vo.id|sumRentCost='','',###,'','',''}</div>
            </div>
            <table id="dg" title="消费记录(双击编辑)" style="width:990px;height:auto"
                            toolbar="#toolbar" pagination="true" striped="true"
                            rownumbers="true" fitColumns="true" singleSelect="true" >
                    <thead>
                        <tr>
                            <th field="id" width="15" hidden="true">编号</th>
                                    <th field="cost_type" width="6.6%" editor="{type:'combobox',options:{valueField:'cost_type_id',textField:'cost_type_name',data:cost_type_config,required:true}}" formatter="displayCostType">费用类型</th>
                                    
                                    <th field="unit_price" width="3.3%" editor="{type:'validatebox',options:{required:false}}">单价</th>
                                    <th field="start" width="3.3%" editor="{type:'validatebox',options:{required:false}}">开始</th>
                                    <th field="start_time" width="13.2%" editor="{type:'datebox',optioins:{required:false}}">开始时间</th>
                                    <th field="end" width="3.3%" editor="{type:'validatebox',options:{required:false}}">结束</th>
                                    <th field="end_time" width="13.2%" editor="{type:'datebox',optioins:{required:false}}">结束时间</th>
                                    <th field="total" width="4.2%" editor="{type:'validatebox',options:{required:false}}">使用量</th>
                                    <th field="money" width="6.6%" editor="{type:'validatebox',options:{required:true}}">金额</th>
                                    <th field="status_xf" width="6.6%" editor="{type:'combobox',options:{valueField:'cost_status_id',textField:'cost_status_name',data:cost_status_data}}" formatter="displayStatus">状态</th>
                                    <th field="create_time" width="13.2%" >登记时间</th>
                                    <th field="update_time" width="13.2%">更新时间</th>
                                    <th field="remark" width="8%" editor="{type:'textarea'}">备注</th>

                            </tr>
                    </thead>
            </table>
            <div id="toolbar">
                <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:deleterow(1)">删除</a>

            </div>
        </div>
 <div id="rightPart" title="借还记录"> 
       <div class="demo-info" style="margin-bottom:4px">
           <div>&nbsp;</div>
       </div>
            <table id="borrow" title="借还记录(双击编辑)" style="width:900px;height:auto"
                            toolbar="#borrow_toolbar" pagination="true" striped="true" pageSize="10"
                            rownumbers="true" fitColumns="true" singleSelect="true" >
                    <thead>
                        <tr>
                                    <th field="id" width="15" hidden="true">编号</th>
                                    <th field="name" width="40" editor="{type:'validatebox',require:true}">物品</th>
                                    <th field="money" width="40" editor="{type:'validatebox',options:{required:true}}">价值</th>
                                    <th field="start_time" width="90" editor="{type:'datebox',optioins:{required:false}}">开始时间</th>
                                    <th field="end_time" width="90" editor="{type:'datebox',optioins:{required:false}}">归还时间</th>
                                    <th field="status" width="40" editor="{type:'combobox',options:{valueField:'borrow_status_id',textField:'borrow_status_name',data:borrow_status_data}}" formatter="displayBorrowStatus">状态</th>
                                    <th field="create_time" width="90" ">登记时间</th>
                                    <th field="update_time" width="90"">更新时间</th>
                                    <th field="remark" width="80" editor="{type:'textarea'}">备注</th>

                            </tr>
                    </thead>
            </table>
            <div id="borrow_toolbar">
                <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:saverow()">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#borrow').edatagrid('addRow')">新增</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#borrow').edatagrid('cancelRow')">取消</a>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:deleterow()">删除</a>
                    
                    

            </div>
        </div>
        <!--借还记录-->
        <!--联系记录-->
 <div id="rightPart" title="联系记录"> 
       <div class="demo-info" style="margin-bottom:4px">
        <div>&nbsp;</div>
       </div>
       <html:imageBtn name="add" value="新增" click="addContact({$vo.id})" style="impBtn hMargin fLeft shadow" /> 
            <table id="contact" class="list">
                    <thead>
                        <tr>
                            <th>编号</th>
                            <th>标题</th>
                            <th>备注</th>
                            <th>会员</th>
                            <th>创建时间</th>
                            <th>更新时间</th>
                            <th>删除</th>
                         </tr>
                    </thead>
                  <volist name="contacts" id="ca">
                       <tr>
                           <td> {$ca.id}</td>
                           <td> <a href="__APP__/Contact_record/edit/id/{$ca.id}/return_checkin/{$vo.id}">{$ca.title}</a> </td>
                           <td>  <a href="__APP__/Contact_record/edit/id/{$ca.id}/return_checkin/{$vo.id}">{$ca.content|getPureTxt=90}</a></td>
                           <td>{$ca.member_id|getModelName='Member'}</td>
                           <td>{$ca.create_time|toDate}</td>
                           <td>{$ca.update_time|toDate}</td>
                           <td><a href="__APP__/Contact_record/foreverdelete/id/{$ca.id}">删除</a></td> 
                       </tr>
             </volist>
                </table>
        </div>
        <!--联系记录-->
    </div><!---tap end-->

</div>
</div>


<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/Js/easyui/plugins/jquery.edatagrid.js"></script>
        <script type="text/javascript" src="__PUBLIC__/Js/easyui/easyui-lang-zh_CN.js"></script>
<script language="JavaScript">
<!--
function showdetail(obj){
        var order_id = obj.value;
        jQuery.post(
        URL+'/getMemberByOrder',
        {order_id:order_id},
        function(data){
            data = data.data;
            $('#member_id').attr('value',data.member_id);
            $('#member_name').attr('value',data.member);
            $("input[name='start_time']").attr('value',data.start_time);
            $("input[name='end_time']").attr('value',data.end_time);
            $('#person_name').attr('value',data.cust_name+',');
            $('#advance_pay').attr('value',data.advance_pay);
            $('#house').attr('value',data.house);
            $('#room_id').parent().remove();
            $('#room_tr').append(data.rooms);
        },
        'json'
        );
};
</script>
<script type="text/javascript">
           var cost_status_data = <php>echo getConfigDataJson("coststatus","cost_status_id","cost_status_name");</php>;
           var cost_type_config = <php>echo getConfigDataJson("cost_type","cost_type_id","cost_type_name");</php>;
           var borrow_status_data = <php>echo getConfigDataJson("borrowstatus","borrow_status_id","borrow_status_name");</php>;
		$(function(){
			$('#dg').edatagrid({
                                idField:'id',
				url: '__URL__/getCostsJson/checkin_id/{$_GET.id}',
				saveUrl: '__URL__/addCost/checkin_id/{$_GET.id}',
				updateUrl: '__APP__/Costdetail/ajaxUpdate'
			}
                );
                    //borrows
                    $('#borrow').edatagrid({
                                idField:'id',
				url: '__URL__/getBorrowsJson/checkin_id/{$_GET.id}',
				saveUrl: '__URL__/addCost/checkin_id/{$_GET.id}/type/2',
				updateUrl: '__APP__/Borrow/update'
			}
                );

		});
               function displayStatus(value){
                    for(var i=0; i<cost_status_data.length; i++){
                    if (cost_status_data[i].cost_status_id == value) return cost_status_data[i].cost_status_name;
                }
                return value;
               }

               function displayBorrowStatus(value){
                    for(var i=0; i<borrow_status_data.length; i++){
                    if (borrow_status_data[i].borrow_status_id == value) return borrow_status_data[i].borrow_status_name;
                }
                return value;
               }

               function displayCostType(value){
                    for(var i=0; i<cost_type_config.length; i++){
                    if (cost_type_config[i].cost_type_id == value) return cost_type_config[i].cost_type_name;
                }
                return value;
               }
               function deleterow(type){
                   var dg = "";
                   var model = "";
                   if(type == 1){
                      dg = $('#dg');
                      model = "Costdetail";
                   }else{
                       dg = $('#borrow');
                       model = "Borrow";
                   }
                  var row = dg.edatagrid('getSelected');
                  var index = dg.edatagrid('getRowIndex', row);
                  var delete_id = row.id;
			$.messager.confirm('Confirm','确定删除?',function(r){
				if (r){
					dg.edatagrid('deleteRow', index);
                                        $.post("__APP__/"+model+"/foreverdelete/id/"+delete_id);
                                        //location.href= "__APP__/"+model+"/foreverdelete/id/"+delete_id;
					updateActions();

				}
			});
		}

                function saverow(){
                    $('#borrow').edatagrid('saveRow');
                    $('#borrow').edatagrid('reload');
                }
  function addContact(id){
    location.href ="__APP__/Contact_record/add/checkin_id/"+id;
  }

	</script>
	
